package com.ruoyi.web.controller.system.employee.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.employee.domain.ServiceEmployeeAttendance;
import com.ruoyi.system.employee.service.IServiceEmployeeAttendanceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工出勤情况统计Controller
 * 
 * @author Administrator
 * @date 2021-03-06
 */
@Controller
@RequestMapping("/employee/attendance")
public class ServiceEmployeeAttendanceController extends BaseController
{
    private String prefix = "employee/attendance";

    @Autowired
    private IServiceEmployeeAttendanceService serviceEmployeeAttendanceService;

    @RequiresPermissions("employee:attendance:view")
    @GetMapping()
    public String attendance()
    {
        return prefix + "/attendance";
    }

    /**
     * 查询员工出勤情况统计列表
     */
    @RequiresPermissions("employee:attendance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ServiceEmployeeAttendance serviceEmployeeAttendance)
    {
        startPage();
        List<ServiceEmployeeAttendance> list = serviceEmployeeAttendanceService.selectServiceEmployeeAttendanceList(serviceEmployeeAttendance);
        return getDataTable(list);
    }

    /**
     * 导出员工出勤情况统计列表
     */
    @RequiresPermissions("employee:attendance:export")
    @Log(title = "员工出勤情况统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ServiceEmployeeAttendance serviceEmployeeAttendance)
    {
        List<ServiceEmployeeAttendance> list = serviceEmployeeAttendanceService.selectServiceEmployeeAttendanceList(serviceEmployeeAttendance);
        ExcelUtil<ServiceEmployeeAttendance> util = new ExcelUtil<ServiceEmployeeAttendance>(ServiceEmployeeAttendance.class);
        return util.exportExcel(list, "attendance");
    }

    /**
     * 新增员工出勤情况统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工出勤情况统计
     */
    @RequiresPermissions("employee:attendance:add")
    @Log(title = "员工出勤情况统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ServiceEmployeeAttendance serviceEmployeeAttendance)
    {
        return toAjax(serviceEmployeeAttendanceService.insertServiceEmployeeAttendance(serviceEmployeeAttendance));
    }

    /**
     * 修改员工出勤情况统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ServiceEmployeeAttendance serviceEmployeeAttendance = serviceEmployeeAttendanceService.selectServiceEmployeeAttendanceById(id);
        mmap.put("serviceEmployeeAttendance", serviceEmployeeAttendance);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工出勤情况统计
     */
    @RequiresPermissions("employee:attendance:edit")
    @Log(title = "员工出勤情况统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ServiceEmployeeAttendance serviceEmployeeAttendance)
    {
        return toAjax(serviceEmployeeAttendanceService.updateServiceEmployeeAttendance(serviceEmployeeAttendance));
    }

    /**
     * 删除员工出勤情况统计
     */
    @RequiresPermissions("employee:attendance:remove")
    @Log(title = "员工出勤情况统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(serviceEmployeeAttendanceService.deleteServiceEmployeeAttendanceByIds(ids));
    }
}
